home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / vibrant / vibbutns.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-05  |  30.5 KB  |  1,304 lines  |  [TEXT/R*ch]

  1. /*   vibbutns.c
  2. * ===========================================================================
  3. *
  4. *                            PUBLIC DOMAIN NOTICE
  5. *            National Center for Biotechnology Information (NCBI)
  6. *
  7. *  This software/database is a "United States Government Work" under the
  8. *  terms of the United States Copyright Act.  It was written as part of
  9. *  the author's official duties as a United States Government employee and
  10. *  thus cannot be copyrighted.  This software/database is freely available
  11. *  to the public for use. The National Library of Medicine and the U.S.
  12. *  Government do not place any restriction on its use or reproduction.
  13. *  We would, however, appreciate having the NCBI and the author cited in
  14. *  any work or product based on this material
  15. *
  16. *  Although all reasonable efforts have been taken to ensure the accuracy
  17. *  and reliability of the software and data, the NLM and the U.S.
  18. *  Government do not and cannot warrant the performance or results that
  19. *  may be obtained by using this software or data. The NLM and the U.S.
  20. *  Government disclaim all warranties, express or implied, including
  21. *  warranties of performance, merchantability or fitness for any particular
  22. *  purpose.
  23. *
  24. * ===========================================================================
  25. *
  26. * File Name:  vibbutns.c
  27. *
  28. * Author:  Jonathan Kans
  29. *
  30. * Version Creation Date:   7/1/91
  31. *
  32. * $Revision: 2.12 $
  33. *
  34. * File Description: 
  35. *       Vibrant button functions
  36. *
  37. * Modifications:  
  38. * --------------------------------------------------------------------------
  39. * Date     Name        Description of modification
  40. * -------  ----------  -----------------------------------------------------
  41. *
  42. *
  43. * ==========================================================================
  44. */
  45.  
  46. #include <vibtypes.h>
  47. #include <vibprocs.h>
  48. #include <vibincld.h>
  49.  
  50. #ifdef WIN_MAC
  51. #define Nlm_ControlTool ControlHandle
  52. #endif
  53.  
  54. #ifdef WIN_MSWIN
  55. #define Nlm_ControlTool HWND
  56. #endif
  57.  
  58. #ifdef WIN_MOTIF
  59. #define Nlm_ControlTool Widget
  60. #endif
  61.  
  62. typedef  struct  Nlm_buttondata {
  63.   Nlm_ControlTool  handle;
  64.   Nlm_Int2         border;
  65.   Nlm_Int2         offset;
  66.   Nlm_Boolean      defaultBtn;
  67. } Nlm_ButtonData;
  68.  
  69. typedef  struct  Nlm_buttonrec {
  70.   Nlm_GraphicRec  graphicR;
  71.   Nlm_ButtonData  button;
  72. } Nlm_ButtonRec, PNTR Nlm_BtnPtr;
  73.  
  74. static Nlm_GphPrcsPtr  gphprcsptr = NULL;
  75.  
  76. static Nlm_GphPrcsPtr  pushProcs;
  77. static Nlm_GphPrcsPtr  defaultProcs;
  78. static Nlm_GphPrcsPtr  checkProcs;
  79. static Nlm_GphPrcsPtr  radioProcs;
  80.  
  81. static Nlm_ButtoN      recentButton = NULL;
  82. static Nlm_ButtonData  recentButtonData;
  83.  
  84. #ifdef WIN_MSWIN
  85. static WNDPROC         lpfnNewButtonProc = NULL;
  86. static WNDPROC         lpfnOldButtonProc = NULL;
  87. static Nlm_Boolean     handlechar;
  88. #endif
  89.  
  90. static void Nlm_LoadButtonData (Nlm_ButtoN b, Nlm_ControlTool hdl,
  91.                                 Nlm_Int2 bdr, Nlm_Int2 ofs,
  92.                                 Nlm_Boolean dflt)
  93.  
  94. {
  95.   Nlm_BtnPtr      bp;
  96.   Nlm_ButtonData  PNTR ptr;
  97.  
  98.   if (b != NULL) {
  99.     bp = (Nlm_BtnPtr) Nlm_HandLock (b);
  100.     ptr = &(bp->button);
  101.     ptr->handle = hdl;
  102.     ptr->border = bdr;
  103.     ptr->offset = ofs;
  104.     ptr->defaultBtn = dflt;
  105.     Nlm_HandUnlock (b);
  106.     recentButton = NULL;
  107.   }
  108. }
  109.  
  110. static void Nlm_SetButtonData (Nlm_ButtoN b, Nlm_ButtonData * bdata)
  111.  
  112. {
  113.   Nlm_BtnPtr  bp;
  114.  
  115.   if (b != NULL && bdata != NULL) {
  116.     bp = (Nlm_BtnPtr) Nlm_HandLock (b);
  117.     bp->button = *bdata;
  118.     Nlm_HandUnlock (b);
  119.     recentButton = b;
  120.     recentButtonData = *bdata;
  121.   }
  122. }
  123.  
  124. static void Nlm_GetButtonData (Nlm_ButtoN b, Nlm_ButtonData * bdata)
  125.  
  126. {
  127.   Nlm_BtnPtr  bp;
  128.  
  129.   if (b != NULL && bdata != NULL) {
  130.     if (b == recentButton && NLM_RISKY) {
  131.       *bdata = recentButtonData;
  132.     } else {
  133.       bp = (Nlm_BtnPtr) Nlm_HandLock (b);
  134.       *bdata = bp->button;
  135.       Nlm_HandUnlock (b);
  136.       recentButton = b;
  137.       recentButtonData = *bdata;
  138.     }
  139.   }
  140. }
  141.  
  142. static Nlm_ControlTool Nlm_GetButtonHandle (Nlm_ButtoN b)
  143.  
  144. {
  145.   Nlm_ButtonData  bdata;
  146.  
  147.   Nlm_GetButtonData (b, &bdata);
  148.   return bdata.handle;
  149. }
  150.  
  151. static Nlm_Int2 Nlm_GetButtonBorder (Nlm_ButtoN b)
  152.  
  153. {
  154.   Nlm_ButtonData  bdata;
  155.  
  156.   Nlm_GetButtonData (b, &bdata);
  157.   return bdata.border;
  158. }
  159.  
  160. static Nlm_Int2 Nlm_GetButtonOffset (Nlm_ButtoN b)
  161.  
  162. {
  163.   Nlm_ButtonData  bdata;
  164.  
  165.   Nlm_GetButtonData (b, &bdata);
  166.   return bdata.offset;
  167. }
  168.  
  169. static Nlm_Boolean Nlm_IsDefaultButton (Nlm_ButtoN b)
  170.  
  171. {
  172.   Nlm_ButtonData  bdata;
  173.  
  174.   Nlm_GetButtonData (b, &bdata);
  175.   return bdata.defaultBtn;
  176. }
  177.  
  178. #ifdef WIN_MAC
  179. static Nlm_Boolean Nlm_CommonPtInRect (Nlm_GraphiC b, Nlm_PoinT pt)
  180.  
  181. {
  182.   Nlm_RecT  r;
  183.  
  184.   Nlm_GetRect (b, &r);
  185.   return (Nlm_PtInRect (pt, &r));
  186. }
  187.  
  188. static Nlm_Boolean Nlm_CommonButtonClick (Nlm_GraphiC b, Nlm_PoinT pt, Nlm_Int2 part)
  189.  
  190. {
  191.   Nlm_ControlTool  c;
  192.   Nlm_PointTool    ptool;
  193.  
  194.   c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
  195.   Nlm_PoinTToPointTool (pt, &ptool);
  196.   return (part == TrackControl (c, ptool, NULL));
  197. }
  198.  
  199. static Nlm_Boolean Nlm_PushClick (Nlm_GraphiC b, Nlm_PoinT pt)
  200.  
  201. {
  202.   Nlm_Boolean  rsult;
  203.  
  204.   rsult = FALSE;
  205.   if (Nlm_CommonPtInRect (b, pt)) {
  206.     if (Nlm_CommonButtonClick (b, pt, inButton)) {
  207.       Nlm_DoAction (b);
  208.     }
  209.     rsult = TRUE;
  210.   }
  211.   return rsult;
  212. }
  213.  
  214. static Nlm_Boolean Nlm_DefaultClick (Nlm_GraphiC b, Nlm_PoinT pt)
  215.  
  216. {
  217.   Nlm_Boolean  rsult;
  218.  
  219.   rsult = FALSE;
  220.   if (Nlm_CommonPtInRect (b, pt)) {
  221.     if (Nlm_CommonButtonClick (b, pt, inButton)) {
  222.       Nlm_DoAction (b);
  223.     }
  224.     rsult = TRUE;
  225.   }
  226.   return rsult;
  227. }
  228.  
  229. static Nlm_Boolean Nlm_CheckClick (Nlm_GraphiC b, Nlm_PoinT pt)
  230.  
  231. {
  232.   Nlm_Boolean  bool;
  233.   Nlm_GraphiC  g;
  234.   Nlm_Boolean  rsult;
  235.  
  236.   rsult = FALSE;
  237.   if (Nlm_CommonPtInRect (b, pt)) {
  238.     if (Nlm_CommonButtonClick (b, pt, inCheckBox)) {
  239.       bool = Nlm_DoGetStatus (b, 0);
  240.       if (bool) {
  241.         Nlm_DoSetStatus (b, 0, FALSE, FALSE);
  242.       } else {
  243.         Nlm_DoSetStatus (b, 0, TRUE, FALSE);
  244.       }
  245.       Nlm_DoAction (b);
  246.       g = Nlm_GetParent (b);
  247.       Nlm_DoAction (g);
  248.     }
  249.     rsult = TRUE;
  250.   }
  251.   return rsult;
  252. }
  253.  
  254. static Nlm_Boolean Nlm_RadioClick (Nlm_GraphiC b, Nlm_PoinT pt)
  255.  
  256. {
  257.   Nlm_Boolean  bool;
  258.   Nlm_GraphiC  g;
  259.   Nlm_Boolean  rsult;
  260.  
  261.   rsult = FALSE;
  262.   if (Nlm_CommonPtInRect (b, pt)) {
  263.     if (Nlm_CommonButtonClick (b, pt, inCheckBox)) {
  264.       bool = Nlm_DoGetStatus (b, 0);
  265.       if (! bool) {
  266.         g = Nlm_GetParent (b);
  267.         Nlm_ClearItemsInGroup (g, b, FALSE);
  268.         Nlm_DoSetStatus (b, 0, TRUE, FALSE);
  269.         Nlm_DoAction (b);
  270.         Nlm_DoAction (g);
  271.       }
  272.     }
  273.     rsult = TRUE;
  274.   }
  275.   return rsult;
  276. }
  277. #endif
  278.  
  279. #ifdef WIN_MSWIN
  280. static Nlm_Boolean Nlm_PushCommand (Nlm_GraphiC b)
  281.  
  282. {
  283.   Nlm_DoAction (b);
  284.   return TRUE;
  285. }
  286.  
  287. static Nlm_Boolean Nlm_DefaultCommand (Nlm_GraphiC b)
  288.  
  289. {
  290.   Nlm_DoAction (b);
  291.   return TRUE;
  292. }
  293.  
  294. static Nlm_Boolean Nlm_CheckCommand (Nlm_GraphiC b)
  295.  
  296. {
  297.   Nlm_Boolean  bool;
  298.   Nlm_GraphiC  g;
  299.  
  300.   bool = Nlm_DoGetStatus (b, 0);
  301.   if (bool) {
  302.     Nlm_DoSetStatus (b, 0, FALSE, FALSE);
  303.   } else {
  304.     Nlm_DoSetStatus (b, 0, TRUE, FALSE);
  305.   }
  306.   Nlm_DoAction (b);
  307.   g = Nlm_GetParent (b);
  308.   Nlm_DoAction (g);
  309.   return TRUE;
  310. }
  311.  
  312. static Nlm_Boolean Nlm_RadioCommand (Nlm_GraphiC b)
  313.  
  314. {
  315.   Nlm_Boolean  bool;
  316.   Nlm_GraphiC  g;
  317.  
  318.   bool = Nlm_DoGetStatus (b, 0);
  319.   if (! bool) {
  320.     g = Nlm_GetParent (b);
  321.     Nlm_ClearItemsInGroup (g, b, FALSE);
  322.     Nlm_DoSetStatus (b, 0, TRUE, FALSE);
  323.     Nlm_DoAction (b);
  324.     Nlm_DoAction (g);
  325.   }
  326.   return TRUE;
  327. }
  328. #endif
  329.  
  330. #ifdef WIN_MOTIF
  331. static void Nlm_PushCallback (Nlm_GraphiC b)
  332.  
  333. {
  334.   Nlm_DoAction (b);
  335. }
  336.  
  337. static void Nlm_DefaultCallback (Nlm_GraphiC b)
  338.  
  339. {
  340.   Nlm_DoAction (b);
  341. }
  342.  
  343. static void Nlm_CheckCallback (Nlm_GraphiC b)
  344.  
  345. {
  346.   Nlm_Boolean      bool;
  347.   Nlm_ControlTool  c;
  348.   Nlm_GraphiC      g;
  349.  
  350.   c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
  351.   bool = Nlm_DoGetStatus (b, 0);
  352.   if (! bool) {
  353.     Nlm_DoSetStatus (b, 0, FALSE, FALSE);
  354.   } else {
  355.     Nlm_DoSetStatus (b, 0, TRUE, FALSE);
  356.   }
  357.   Nlm_DoAction (b);
  358.   g = Nlm_GetParent (b);
  359.   Nlm_DoAction (g);
  360. }
  361.  
  362. static void Nlm_RadioCallback (Nlm_GraphiC b)
  363.  
  364. {
  365.   Nlm_Boolean      bool;
  366.   Nlm_ControlTool  c;
  367.   Nlm_GraphiC      g;
  368.  
  369.   c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
  370.   bool = Nlm_DoGetStatus (b, 0);
  371.   if (bool) {
  372.     g = Nlm_GetParent (b);
  373.     Nlm_ClearItemsInGroup (g, b, FALSE);
  374.     Nlm_DoSetStatus (b, 0, TRUE, FALSE);
  375.     Nlm_DoAction (b);
  376.     Nlm_DoAction (g);
  377.   } else {
  378.     Nlm_DoSetStatus (b, 0, TRUE, FALSE);
  379.   }
  380. }
  381. #endif
  382.  
  383. #ifdef WIN_MAC
  384. static Nlm_Boolean Nlm_DefaultKey (Nlm_GraphiC b, Nlm_Char ch)
  385.  
  386. {
  387.   Nlm_ControlTool  c;
  388.   Nlm_Int4         res;
  389.   Nlm_Boolean      rsult;
  390.  
  391.   rsult = FALSE;
  392.   if (ch == '\15' || ch == '\3') {
  393.     c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
  394.     HiliteControl (c, 1);
  395.     Delay (8, &res);
  396.     HiliteControl (c, 0);
  397.     Nlm_DoSetStatus (b, 0, TRUE, FALSE);
  398.     Nlm_DoAction (b);
  399.     rsult = TRUE;
  400.   }
  401.   return rsult;
  402. }
  403.  
  404. static void Nlm_DrawButton (Nlm_GraphiC b)
  405.  
  406. {
  407.   Nlm_ControlTool  c;
  408.   Nlm_RecT         r;
  409.  
  410.   if (Nlm_GetVisible (b) && Nlm_GetAllParentsVisible (b)) {
  411.     Nlm_GetRect (b, &r);
  412.     if (Nlm_RectInRgn (&r, Nlm_updateRgn)) {
  413.       c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
  414.       Draw1Control (c);
  415.     }
  416.   }
  417. }
  418.  
  419. static void Nlm_DrawDefault (Nlm_GraphiC b)
  420.  
  421. {
  422.   Nlm_ControlTool  c;
  423.   Nlm_RecT         r;
  424.  
  425.   if (Nlm_GetVisible (b) && Nlm_GetAllParentsVisible (b)) {
  426.     Nlm_GetRect (b, &r);
  427.     Nlm_InsetRect (&r, -4, -4);
  428.     if (Nlm_RectInRgn (&r, Nlm_updateRgn)) {
  429.       PenSize (3, 3);
  430.       Nlm_FrameRoundRect (&r, 16, 16);
  431.       PenNormal ();
  432.       c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
  433.       Draw1Control (c);
  434.     }
  435.   }
  436. }
  437. #endif
  438.  
  439. static void Nlm_ShowButton (Nlm_GraphiC b, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  440.  
  441. {
  442.   Nlm_ControlTool  c;
  443.   Nlm_WindoW       tempPort;
  444.  
  445.   if (setFlag) {
  446.     Nlm_SetVisible (b, TRUE);
  447.   }
  448.   if (Nlm_GetVisible (b) && Nlm_AllParentsButWindowVisible (b)) {
  449.     tempPort = Nlm_SavePortIfNeeded (b, savePort);
  450.     c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
  451. #ifdef WIN_MAC
  452.     ShowControl (c);
  453.     Nlm_DoDraw (b);
  454. #endif
  455. #ifdef WIN_MSWIN
  456.     ShowWindow (c, SW_SHOW);
  457.     UpdateWindow (c);
  458. #endif
  459. #ifdef WIN_MOTIF
  460.     XtManageChild (c);
  461. #endif
  462.     Nlm_RestorePort (tempPort);
  463.   }
  464. }
  465.  
  466. static void Nlm_HideButton (Nlm_GraphiC b, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  467.  
  468. {
  469.   Nlm_ControlTool  c;
  470.   Nlm_WindoW       tempPort;
  471. #ifdef WIN_MAC
  472.   Nlm_Int2         border;
  473.   Nlm_RecT         r;
  474. #endif
  475.  
  476.   if (setFlag) {
  477.     Nlm_SetVisible (b, FALSE);
  478.   }
  479.   tempPort = Nlm_SavePortIfNeeded (b, savePort);
  480.   c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
  481. #ifdef WIN_MAC
  482.   border = Nlm_GetButtonBorder ((Nlm_ButtoN) b);
  483.   HideControl (c);
  484.   if (Nlm_GetAllParentsVisible (b)) {
  485.     Nlm_GetRect (b, &r);
  486.     Nlm_InsetRect (&r, -1 - border, -1 - border);
  487.     Nlm_EraseRect (&r);
  488.     Nlm_ValidRect (&r);
  489.   }
  490. #endif
  491. #ifdef WIN_MSWIN
  492.   ShowWindow (c, SW_HIDE);
  493.   UpdateWindow (c);
  494. #endif
  495. #ifdef WIN_MOTIF
  496.   XtUnmanageChild (c);
  497. #endif
  498.   Nlm_RestorePort (tempPort);
  499. }
  500.  
  501. static void Nlm_EnableButton (Nlm_GraphiC b, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  502.  
  503. {
  504.   Nlm_ControlTool  c;
  505.   Nlm_WindoW       tempPort;
  506.  
  507.   if (setFlag) {
  508.     Nlm_SetEnabled (b, TRUE);
  509.   }
  510.   if (Nlm_GetEnabled (b) && Nlm_GetAllParentsEnabled (b)) {
  511.     tempPort = Nlm_SavePortIfNeeded (b, savePort);
  512.     c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
  513. #ifdef WIN_MAC
  514.     HiliteControl (c, 0);
  515. #endif
  516. #ifdef WIN_MSWIN
  517.     EnableWindow (c, TRUE);
  518. #endif
  519. #ifdef WIN_MOTIF
  520.     XtVaSetValues (c, XmNsensitive, TRUE, NULL);
  521. #endif
  522.     Nlm_RestorePort (tempPort);
  523.   }
  524. }
  525.  
  526. static void Nlm_DisableButton (Nlm_GraphiC b, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  527.  
  528. {
  529.   Nlm_ControlTool  c;
  530.   Nlm_WindoW       tempPort;
  531.  
  532.   if (setFlag) {
  533.     Nlm_SetEnabled (b, FALSE);
  534.   }
  535.   tempPort = Nlm_SavePortIfNeeded (b, savePort);
  536.   c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
  537. #ifdef WIN_MAC
  538.   HiliteControl (c, 255);
  539. #endif
  540. #ifdef WIN_MSWIN
  541.   EnableWindow (c, FALSE);
  542. #endif
  543. #ifdef WIN_MOTIF
  544.   XtVaSetValues (c, XmNsensitive, FALSE, NULL);
  545. #endif
  546.   Nlm_RestorePort (tempPort);
  547. }
  548.  
  549. static void Nlm_RemoveButton (Nlm_GraphiC b, Nlm_Boolean savePort)
  550.  
  551. {
  552.   Nlm_ControlTool  c;
  553.   Nlm_WindoW       tempPort;
  554.  
  555.   tempPort = Nlm_SavePortIfNeeded (b, savePort);
  556.   c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
  557. #ifdef WIN_MAC
  558.   DisposeControl (c);
  559. #endif
  560. #ifdef WIN_MSWIN
  561.   RemoveProp (c, (LPSTR) "Nlm_VibrantProp");
  562.   DestroyWindow (c);
  563. #endif
  564. #ifdef WIN_MOTIF
  565.   XtDestroyWidget (c);
  566. #endif
  567.   Nlm_RemoveLink (b);
  568.   recentButton = NULL;
  569.   Nlm_RestorePort (tempPort);
  570. }
  571.  
  572. static void Nlm_RemoveDefaultButton (Nlm_GraphiC b, Nlm_Boolean savePort)
  573.  
  574. {
  575.   Nlm_ControlTool  c;
  576.   Nlm_WindoW       tempPort;
  577. #ifdef WIN_MOTIF
  578.   Nlm_WindoW       w;
  579.   Nlm_WindowTool   wptr;
  580. #endif
  581.  
  582.   tempPort = Nlm_SavePortIfNeeded (b, savePort);
  583.   c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
  584. #ifdef WIN_MAC
  585.   DisposeControl (c);
  586. #endif
  587. #ifdef WIN_MSWIN
  588.   RemoveProp (c, (LPSTR) "Nlm_VibrantProp");
  589.   DestroyWindow (c);
  590. #endif
  591. #ifdef WIN_MOTIF
  592.   w = Nlm_ParentWindow (b);
  593.   wptr = Nlm_ParentWindowPtr (b);
  594.   if (Nlm_GetWindowDefaultButton (w) == (Nlm_ButtoN) b) {
  595.     Nlm_SetWindowDefaultButton (w, (Nlm_ButtoN) b);
  596.     XtVaSetValues (wptr, XmNdefaultButton, NULL, NULL);
  597.   }
  598.   XtDestroyWidget (c);
  599. #endif
  600.   Nlm_RemoveLink (b);
  601.   recentButton = NULL;
  602.   Nlm_RestorePort (tempPort);
  603. }
  604.  
  605. static void Nlm_SetButtonTitle (Nlm_GraphiC b, Nlm_Int2 item,
  606.                                 Nlm_CharPtr title, Nlm_Boolean savePort)
  607.  
  608. {
  609.   Nlm_ControlTool  c;
  610.   Nlm_Char         temp [256];
  611.   Nlm_WindoW       tempPort;
  612. #ifdef WIN_MOTIF
  613.   XmString         label;
  614. #endif
  615.  
  616.   tempPort = Nlm_SavePortIfNeeded (b, savePort);
  617.   c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
  618.   Nlm_StringNCpy (temp, title, sizeof (temp));
  619. #ifdef WIN_MAC
  620.   Nlm_CtoPstr (temp);
  621.   SetCTitle (c, (StringPtr) temp);
  622. #endif
  623. #ifdef WIN_MSWIN
  624.   SetWindowText (c, temp);
  625. #endif
  626. #ifdef WIN_MOTIF
  627.   label = XmStringCreateSimple (temp);
  628.   XtVaSetValues (c, XmNlabelString, label, NULL);
  629.   XmStringFree (label);
  630. #endif
  631.   Nlm_RestorePort (tempPort);
  632. }
  633.  
  634. static void Nlm_GetButtonTitle (Nlm_GraphiC b, Nlm_Int2 item,
  635.                                 Nlm_CharPtr title, Nlm_sizeT maxsize)
  636.  
  637. {
  638.   Nlm_ControlTool  c;
  639.   Nlm_Char         temp [256];
  640. #ifdef WIN_MOTIF
  641.   XmString         label;
  642.   char             *text;
  643. #endif
  644.  
  645.   c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
  646. #ifdef WIN_MAC
  647.   GetCTitle (c, (StringPtr) temp);
  648.   Nlm_PtoCstr (temp);
  649. #endif
  650. #ifdef WIN_MSWIN
  651.   GetWindowText (c, temp, sizeof (temp));
  652. #endif
  653. #ifdef WIN_MOTIF
  654.   XtVaGetValues (c, XmNlabelString, &label, NULL);
  655.   temp [0] = '\0';
  656.   if (XmStringGetLtoR (label, XmSTRING_DEFAULT_CHARSET, &text)) {
  657.     Nlm_StringNCpy (temp, text, sizeof (temp));
  658.     XtFree (text);
  659.   }
  660. #endif
  661.   Nlm_StringNCpy (title, temp, maxsize);
  662. }
  663.  
  664. static void Nlm_SetButtonStatus (Nlm_GraphiC b, Nlm_Int2 item,
  665.                                  Nlm_Boolean set, Nlm_Boolean savePort)
  666.  
  667. {
  668.   Nlm_ControlTool  c;
  669.   Nlm_WindoW       tempPort;
  670.   Nlm_Int2         val;
  671.  
  672.   tempPort = Nlm_SavePortIfNeeded (b, savePort);
  673.   c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
  674.   if (set) {
  675.     val = 1;
  676.   } else {
  677.     val = 0;
  678.   }
  679. #ifdef WIN_MAC
  680.   SetCtlValue (c, val);
  681. #endif
  682. #ifdef WIN_MSWIN
  683.   Button_SetCheck (c, val);
  684. #endif
  685. #ifdef WIN_MOTIF
  686.   XmToggleButtonSetState (c, (Boolean) set, FALSE);
  687. #endif
  688.   Nlm_RestorePort (tempPort);
  689. }
  690.  
  691. static Nlm_Boolean Nlm_GetButtonStatus (Nlm_GraphiC b, Nlm_Int2 item)
  692.  
  693. {
  694.   Nlm_ControlTool  c;
  695.  
  696.   c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
  697. #ifdef WIN_MAC
  698.   return (GetCtlValue (c) != 0);
  699. #endif
  700. #ifdef WIN_MSWIN
  701.   return (Nlm_Boolean) (Button_GetCheck (c) != 0);
  702. #endif
  703. #ifdef WIN_MOTIF
  704.   return (Nlm_Boolean) (XmToggleButtonGetState (c) != FALSE);
  705. #endif
  706. }
  707.  
  708. #ifdef WIN_MAC
  709. static void Nlm_InvalButton (Nlm_GraphiC b, Nlm_Int2 border)
  710.  
  711. {
  712.   Nlm_RecT  r;
  713.  
  714.   if (Nlm_GetVisible (b) && Nlm_GetAllParentsVisible (b)) {
  715.     Nlm_GetRect (b, &r);
  716.     Nlm_InsetRect (&r, -1 - border, -1 - border);
  717.     Nlm_InvalRect (&r);
  718.   }
  719. }
  720. #endif
  721.  
  722. static void Nlm_SetButtonPosition (Nlm_GraphiC b, Nlm_RectPtr r, Nlm_Boolean savePort)
  723.  
  724. {
  725.   Nlm_ButtonData   bdata;
  726.   Nlm_ControlTool  c;
  727.   Nlm_RecT         oldRect;
  728.   Nlm_WindoW       tempPort;
  729. #ifdef WIN_MAC
  730.   Nlm_Int2         border;
  731. #endif
  732. #ifdef WIN_MOTIF
  733.   Nlm_Int2         offset;
  734. #endif
  735.  
  736.   if (r != NULL) {
  737.     Nlm_DoGetPosition (b, &oldRect);
  738.     if (! Nlm_EqualRect (r, &oldRect)) {
  739.       tempPort = Nlm_SavePortIfNeeded (b, savePort);
  740.       Nlm_GetButtonData ((Nlm_ButtoN) b, &bdata);
  741.       c = bdata.handle;
  742. #ifdef WIN_MAC
  743.       border = bdata.border;
  744.       Nlm_InvalButton (b, border);
  745.       MoveControl (c, r->left, r->top);
  746.       SizeControl (c, r->right - r->left, r->bottom - r->top);
  747.       Nlm_SetRect (b, r);
  748.       Nlm_InvalButton (b, border);
  749. #endif
  750. #ifdef WIN_MSWIN
  751.       MoveWindow (c, r->left, r->top, r->right - r->left, r->bottom - r->top, TRUE);
  752.       Nlm_SetRect (b, r);
  753.       UpdateWindow (c);
  754. #endif
  755. #ifdef WIN_MOTIF
  756.       offset = bdata.offset;
  757.       XtVaSetValues (c,
  758.                      XmNx, (Position) r->left - offset,
  759.                      XmNy, (Position) r->top - offset,
  760.                      XmNwidth, (Dimension) (r->right - r->left),
  761.                      XmNheight, (Dimension) (r->bottom - r->top), 
  762.                      NULL);
  763.       Nlm_SetRect (b, r);
  764. #endif
  765.       Nlm_RestorePort (tempPort);
  766.     }
  767.   }
  768. }
  769.  
  770. static void Nlm_GetButtonPosition (Nlm_GraphiC b, Nlm_RectPtr r)
  771.  
  772. {
  773.   if (r != NULL) {
  774.     Nlm_GetRect (b, r);
  775.   }
  776. }
  777.  
  778. static Nlm_GraphiC Nlm_DefaultGainFocus (Nlm_GraphiC b, Nlm_Char ch, Nlm_Boolean savePort)
  779.  
  780. {
  781. #ifdef WIN_MAC
  782.   return NULL;
  783. #endif
  784. #ifdef WIN_MSWIN
  785.   Nlm_GraphiC   rsult;
  786.  
  787.   rsult = NULL;
  788.   if (ch == '\n' || ch == '\r') {
  789.     if (Nlm_GetVisible (b) && Nlm_GetAllParentsVisible (b) &&
  790.         Nlm_GetEnabled (b) && Nlm_GetAllParentsEnabled (b)) {
  791.       Nlm_DoAction (b);
  792.       rsult = b;
  793.     }
  794.   }
  795.   return rsult;
  796. #endif
  797. #ifdef WIN_MOTIF
  798.   return NULL;
  799. #endif
  800. }
  801.  
  802. #ifdef WIN_MSWIN
  803. /* Message cracker functions */
  804.  
  805. static void MyCls_OnChar (HWND hwnd, UINT ch, int cRepeat)
  806.  
  807. {
  808.   Nlm_ButtoN  b;
  809.  
  810.   b = (Nlm_ButtoN) GetProp (hwnd, (LPSTR) "Nlm_VibrantProp");
  811.   handlechar = FALSE;
  812.   if (ch == '\t') {
  813.     Nlm_DoSendFocus ((Nlm_GraphiC) b, (Nlm_Char) ch);
  814.   } else if (ch == '\n' || ch == '\r') {
  815.     if (Nlm_IsDefaultButton (b)) {
  816.       Nlm_DoGainFocus ((Nlm_GraphiC) b, (Nlm_Char) ch, FALSE);
  817.     } else {
  818.       Nlm_DoSendFocus ((Nlm_GraphiC) b, (Nlm_Char) ch);
  819.     }
  820.   } else {
  821.     handlechar = TRUE;
  822.   }
  823. }
  824.  
  825. LRESULT CALLBACK EXPORT ButtonProc (HWND hwnd, UINT message,
  826.                                     WPARAM wParam, LPARAM lParam)
  827.  
  828. {
  829.   Nlm_ButtoN  b;
  830.   LRESULT     rsult;
  831.   HDC         tempHDC;
  832.   HWND        tempHWnd;
  833.  
  834.   if (Nlm_VibrantDisabled ()) {
  835.     return CallWindowProc (lpfnOldButtonProc, hwnd, message, wParam, lParam);
  836.   }
  837.  
  838.   rsult = 0;
  839.   tempHWnd = Nlm_currentHWnd;
  840.   tempHDC = Nlm_currentHDC;
  841.   b = (Nlm_ButtoN) GetProp (hwnd, (LPSTR) "Nlm_VibrantProp");
  842.   Nlm_theWindow = Nlm_GetParentWindow ((Nlm_GraphiC) b);
  843.   Nlm_currentHWnd = GetParent (hwnd);
  844.   Nlm_currentHDC = Nlm_ParentWindowPort ((Nlm_GraphiC) b);
  845.   Nlm_currentWindowTool = hwnd;
  846.   Nlm_currentKey = '\0';
  847.   Nlm_currentWParam = wParam;
  848.   Nlm_currentLParam = lParam;
  849.   Nlm_cmmdKey = FALSE;
  850.   Nlm_ctrlKey = FALSE;
  851.   Nlm_optKey = FALSE;
  852.   Nlm_shftKey = FALSE;
  853.   Nlm_dblClick = FALSE;
  854.  
  855.   switch (message) {
  856.     case WM_CHAR:
  857.       HANDLE_WM_CHAR (hwnd, wParam, lParam, MyCls_OnChar);
  858.       if (handlechar) {
  859.         rsult = CallWindowProc (lpfnOldButtonProc, hwnd, message, wParam, lParam);
  860.       }
  861.       break;
  862.     default:
  863.       rsult = CallWindowProc (lpfnOldButtonProc, hwnd, message, wParam, lParam);
  864.       break;
  865.   }
  866.   Nlm_currentHWnd = tempHWnd;
  867.   Nlm_currentHDC = tempHDC;
  868.   Nlm_currentWindowTool = tempHWnd;
  869.   return rsult;
  870. }
  871. #endif
  872.  
  873. #ifdef WIN_MOTIF
  874. static void Nlm_ButtonCallback (Widget w, XtPointer client_data, XtPointer call_data)
  875.  
  876. {
  877.   Nlm_GraphiC  b;
  878.  
  879.   b = (Nlm_GraphiC) client_data;
  880.   Nlm_DoCallback (b);
  881. }
  882.  
  883. extern void Nlm_MapDefaultButton (Nlm_WindoW w, Nlm_ButtoN b)
  884.  
  885. {
  886.   Nlm_ControlTool  c;
  887.   Nlm_WindowTool   wptr;
  888.  
  889.   if (w != NULL && b != NULL) {
  890.     wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) b);
  891.     c = Nlm_GetButtonHandle (b);
  892.     Nlm_SetWindowDefaultButton (w, b);
  893.     XtVaSetValues (wptr, XmNdefaultButton, c, NULL);
  894.   }
  895. }
  896. #endif
  897.  
  898. #define PUSH_STYLE 1
  899. #define DEFAULT_STYLE 2
  900. #define CHECK_STYLE 3
  901. #define RADIO_STYLE 4
  902.  
  903. static void Nlm_NewButton (Nlm_ButtoN b, Nlm_CharPtr title,
  904.                            Nlm_Int2 type, Nlm_BtnActnProc actn)
  905.  
  906. {
  907.   Nlm_Int2         border;
  908.   Nlm_ControlTool  c;
  909.   Nlm_Boolean      dflt;
  910.   Nlm_Int2         offset;
  911.   Nlm_RecT         r;
  912.   Nlm_Char         temp [256];
  913.   Nlm_WindowTool   wptr;
  914. #ifdef WIN_MAC
  915.   Nlm_Int2         procID;
  916.   Nlm_RectTool     rtool;
  917. #endif
  918. #ifdef WIN_MSWIN
  919.   Nlm_Uint4        style;
  920. #endif
  921. #ifdef WIN_MOTIF
  922.   String           call;
  923.   XmString         label;
  924.   Cardinal         n;
  925.   Nlm_WindoW       w;
  926.   Arg              wargs [15];
  927. #endif
  928.  
  929.   Nlm_GetRect ((Nlm_GraphiC) b, &r);
  930.   wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) b);
  931.   Nlm_StringNCpy (temp, title, sizeof (temp));
  932.   c = NULL;
  933.   border = 0;
  934.   offset = 0;
  935.   dflt = (Nlm_Boolean) (type == DEFAULT_STYLE);
  936. #ifdef WIN_MAC
  937.   Nlm_CtoPstr (temp);
  938.   Nlm_RecTToRectTool (&r, &rtool);
  939.   switch (type) {
  940.     case PUSH_STYLE:
  941.       procID = 0;
  942.       break;
  943.     case DEFAULT_STYLE:
  944.       procID = 0;
  945.       border = 5;
  946.       break;
  947.     case CHECK_STYLE:
  948.       procID = 1;
  949.       break;
  950.     case RADIO_STYLE:
  951.       procID = 2;
  952.       break;
  953.     default:
  954.       procID = 0;
  955.       break;
  956.   }
  957.   c = NewControl (wptr, &rtool, (StringPtr) temp, FALSE, 0, 0, 1, procID, 0);
  958.   Nlm_LoadButtonData (b, c, border, offset, dflt);
  959. #endif
  960. #ifdef WIN_MSWIN
  961.   switch (type) {
  962.     case PUSH_STYLE:
  963.       style = BS_PUSHBUTTON;
  964.       break;
  965.     case DEFAULT_STYLE:
  966.       style = BS_DEFPUSHBUTTON;
  967.       break;
  968.     case CHECK_STYLE:
  969.       style = BS_CHECKBOX;
  970.       break;
  971.     case RADIO_STYLE:
  972.       style = BS_RADIOBUTTON;
  973.       break;
  974.     default:
  975.       style = BS_PUSHBUTTON;
  976.       break;
  977.   }
  978.   c = CreateWindow ("Button", temp, WS_CHILD | style,
  979.                     r.left, r.top, r.right - r.left,
  980.                     r.bottom - r.top, wptr, 0,
  981.                     Nlm_currentHInst, NULL);
  982.   if (c != NULL) {
  983.     SetProp (c, (LPSTR) "Nlm_VibrantProp", (Nlm_HandleTool) b);
  984.   }
  985.   Nlm_LoadButtonData (b, c, border, offset, dflt);
  986.   if (lpfnNewButtonProc == NULL) {
  987.     lpfnNewButtonProc = (WNDPROC) MakeProcInstance ((FARPROC) ButtonProc, Nlm_currentHInst);
  988.   }
  989.   if (lpfnOldButtonProc == NULL) {
  990.     lpfnOldButtonProc = (WNDPROC) GetWindowLong (c, GWL_WNDPROC);
  991.   } else if (lpfnOldButtonProc != (WNDPROC) GetWindowLong (c, GWL_WNDPROC)) {
  992.     Nlm_Message (MSG_ERROR, "ButtonProc subclass error");
  993.   }
  994.   SetWindowLong (c, GWL_WNDPROC, (LONG) lpfnNewButtonProc);
  995. #endif
  996. #ifdef WIN_MOTIF
  997.   label = XmStringCreateSimple (temp);
  998.   if (type == PUSH_STYLE || type == DEFAULT_STYLE) {
  999.     offset = 4;
  1000.   }
  1001.   n = 0;
  1002.   XtSetArg (wargs [n], XmNlabelString, label); n++;
  1003.   XtSetArg (wargs [n], XmNx, (Position) r.left - offset); n++;
  1004.   XtSetArg (wargs [n], XmNy, (Position) r.top - offset); n++;
  1005.   XtSetArg (wargs [n], XmNwidth, (Dimension) (r.right - r.left)); n++;
  1006.   XtSetArg (wargs [n], XmNheight, (Dimension) (r.bottom - r.top)); n++;
  1007.   XtSetArg (wargs [n], XmNmarginHeight, 0); n++;
  1008.   XtSetArg (wargs [n], XmNmarginWidth, 0); n++;
  1009.   XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
  1010.   XtSetArg (wargs [n], XmNhighlightThickness, 0); n++;
  1011.   switch (type) {
  1012.     case PUSH_STYLE:
  1013.       XtSetArg (wargs [n], XmNrecomputeSize, FALSE); n++;
  1014.       c = XmCreatePushButton (wptr, (String) "", wargs, n);
  1015.       call = XmNactivateCallback;
  1016.       break;
  1017.     case DEFAULT_STYLE:
  1018.       XtSetArg (wargs [n], XmNrecomputeSize, FALSE); n++;
  1019.       c = XmCreatePushButton (wptr, (String) "", wargs, n);
  1020.       call = XmNactivateCallback;
  1021.       break;
  1022.     case CHECK_STYLE:
  1023.       XtSetArg (wargs [n], XmNindicatorType, XmN_OF_MANY); n++;
  1024.       XtSetArg (wargs [n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
  1025.       c = XmCreateToggleButton (wptr, (String) "", wargs, n);
  1026.       call = XmNvalueChangedCallback;
  1027.       break;
  1028.     case RADIO_STYLE:
  1029.       XtSetArg (wargs [n], XmNindicatorType, XmONE_OF_MANY); n++;
  1030.       XtSetArg (wargs [n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
  1031.       c = XmCreateToggleButton (wptr, (String) "", wargs, n);
  1032.       call = XmNvalueChangedCallback;
  1033.       break;
  1034.     default:
  1035.       break;
  1036.   }
  1037.   XmStringFree (label);
  1038.   XtAddCallback (c, call, Nlm_ButtonCallback, (XtPointer) b);
  1039.   Nlm_LoadButtonData (b, c, border, offset, dflt);
  1040.   w = Nlm_ParentWindow ((Nlm_GraphiC) b);
  1041.   if (NLM_QUIET) {
  1042.     if (type == DEFAULT_STYLE) {
  1043.       Nlm_SetWindowDefaultButton (w, b);
  1044.     }
  1045.     if (Nlm_WindowHasBeenShown (Nlm_ParentWindow (b))) {
  1046.       XtRealizeWidget (c);
  1047.       if (type == DEFAULT_STYLE) {
  1048.         XtVaSetValues (wptr, XmNdefaultButton, c, NULL);
  1049.       }
  1050.     }
  1051.   } else {
  1052.     XtRealizeWidget (c);
  1053.     if (type == DEFAULT_STYLE) {
  1054.       Nlm_SetWindowDefaultButton (w, b);
  1055.       XtVaSetValues (wptr, XmNdefaultButton, c, NULL);
  1056.     }
  1057.   }
  1058. #endif
  1059.   Nlm_LoadAction ((Nlm_GraphiC) b, (Nlm_ActnProc) actn);
  1060. }
  1061.  
  1062. static Nlm_ButtoN Nlm_CommonButton (Nlm_GrouP prnt, Nlm_CharPtr title,
  1063.                                     Nlm_Int2 type, Nlm_BtnActnProc actn,
  1064.                                     Nlm_GphPrcsPtr classPtr)
  1065.  
  1066. {
  1067.   Nlm_ButtoN  b;
  1068.   Nlm_Int2    hgt;
  1069.   Nlm_PoinT   npt;
  1070.   Nlm_RecT    r;
  1071.   Nlm_WindoW  tempPort;
  1072.   Nlm_Int2    wid;
  1073.  
  1074.   b = NULL;
  1075.   if (prnt != NULL) {
  1076.     tempPort = Nlm_SavePort ((Nlm_GraphiC) prnt);
  1077.     Nlm_GetNextPosition ((Nlm_GraphiC) prnt, &npt);
  1078.     Nlm_SelectFont (Nlm_systemFont);
  1079.     wid = Nlm_StringWidth (title);
  1080. #ifdef WIN_MAC
  1081.   switch (type) {
  1082.     case PUSH_STYLE:
  1083.       hgt = Nlm_stdLineHeight+3;
  1084.       wid += 20;
  1085.       break;
  1086.     case DEFAULT_STYLE:
  1087.       hgt = Nlm_stdLineHeight+3;
  1088.       wid += 20;
  1089.       break;
  1090.     case CHECK_STYLE:
  1091.       hgt = Nlm_stdLineHeight;
  1092.       wid += 20;
  1093.       break;
  1094.     case RADIO_STYLE:
  1095.       hgt = Nlm_stdLineHeight;
  1096.       wid += 20;
  1097.       break;
  1098.     default:
  1099.       hgt = Nlm_stdLineHeight;
  1100.       wid += 20;
  1101.       break;
  1102.   }
  1103. #endif
  1104. #ifdef WIN_MSWIN
  1105.   switch (type) {
  1106.     case PUSH_STYLE:
  1107.       hgt = Nlm_stdLineHeight+8;
  1108.       wid += 20;
  1109.       break;
  1110.     case DEFAULT_STYLE:
  1111.       hgt = Nlm_stdLineHeight+8;
  1112.       wid += 20;
  1113.       break;
  1114.     case CHECK_STYLE:
  1115.       hgt = Nlm_stdLineHeight+3;
  1116.       wid += 20;
  1117.       break;
  1118.     case RADIO_STYLE:
  1119.       hgt = Nlm_stdLineHeight+3;
  1120.       wid += 20;
  1121.       break;
  1122.     default:
  1123.       hgt = Nlm_stdLineHeight;
  1124.       wid += 20;
  1125.       break;
  1126.   }
  1127. #endif
  1128. #ifdef WIN_MOTIF
  1129.   switch (type) {
  1130.     case PUSH_STYLE:
  1131.       hgt = Nlm_stdLineHeight+10;
  1132.       wid += 25;
  1133.       break;
  1134.     case DEFAULT_STYLE:
  1135.       hgt = Nlm_stdLineHeight+10;
  1136.       wid += 25;
  1137.       break;
  1138.     case CHECK_STYLE:
  1139.       hgt = Nlm_stdLineHeight+3;
  1140.       wid += 25;
  1141.       break;
  1142.     case RADIO_STYLE:
  1143.       hgt = Nlm_stdLineHeight+3;
  1144.       wid += 25;
  1145.       break;
  1146.     default:
  1147.       hgt = Nlm_stdLineHeight;
  1148.       wid += 25;
  1149.       break;
  1150.   }
  1151. #endif
  1152.     Nlm_LoadRect (&r, npt.x, npt.y, npt.x+wid, npt.y+hgt);
  1153.     b = (Nlm_ButtoN) Nlm_CreateLink ((Nlm_GraphiC) prnt, &r, sizeof (Nlm_ButtonRec), classPtr);
  1154.     if (b != NULL) {
  1155.       Nlm_NewButton (b, title, type, actn);
  1156.       Nlm_DoAdjustPrnt ((Nlm_GraphiC) b, &r, TRUE, FALSE);
  1157.       Nlm_DoShow ((Nlm_GraphiC) b, TRUE, FALSE);
  1158.     }
  1159.     Nlm_RestorePort (tempPort);
  1160.   }
  1161.   return b;
  1162. }
  1163.  
  1164. extern Nlm_ButtoN Nlm_PushButton (Nlm_GrouP prnt, Nlm_CharPtr title,
  1165.                                   Nlm_BtnActnProc actn)
  1166.  
  1167. {
  1168.   Nlm_ButtoN  b;
  1169.  
  1170.   b = Nlm_CommonButton (prnt, title, PUSH_STYLE, actn, pushProcs);
  1171.   return b;
  1172. }
  1173.  
  1174. extern Nlm_ButtoN Nlm_DefaultButton (Nlm_GrouP prnt, Nlm_CharPtr title,
  1175.                                      Nlm_BtnActnProc actn)
  1176.  
  1177. {
  1178.   Nlm_ButtoN  b;
  1179.  
  1180.   b = Nlm_CommonButton (prnt, title, DEFAULT_STYLE, actn, defaultProcs);
  1181.   return b;
  1182. }
  1183.  
  1184. extern Nlm_ButtoN Nlm_CheckBox (Nlm_GrouP prnt, Nlm_CharPtr title,
  1185.                                 Nlm_BtnActnProc actn)
  1186.  
  1187. {
  1188.   Nlm_ButtoN  b;
  1189.  
  1190.   b = Nlm_CommonButton (prnt, title, CHECK_STYLE, actn, checkProcs);
  1191.   return b;
  1192. }
  1193.  
  1194. extern Nlm_ButtoN Nlm_RadioButton (Nlm_GrouP prnt, Nlm_CharPtr title)
  1195.  
  1196. {
  1197.   Nlm_ButtoN  b;
  1198.  
  1199.   b = Nlm_CommonButton (prnt, title, RADIO_STYLE, NULL, radioProcs);
  1200.   return b;
  1201. }
  1202.  
  1203. extern void Nlm_FreeButtons (void)
  1204.  
  1205. {
  1206.   gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemFree (gphprcsptr);
  1207. }
  1208.  
  1209. extern void Nlm_InitButtons (void)
  1210.  
  1211. {
  1212.   gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemNew (sizeof (Nlm_GphPrcs) * 4);
  1213.  
  1214.   pushProcs = &(gphprcsptr [0]);
  1215. #ifdef WIN_MAC
  1216.   pushProcs->click = Nlm_PushClick;
  1217.   pushProcs->draw = Nlm_DrawButton;
  1218. #endif
  1219. #ifdef WIN_MSWIN
  1220.   pushProcs->command = Nlm_PushCommand;
  1221. #endif
  1222. #ifdef WIN_MOTIF
  1223.   pushProcs->callback = Nlm_PushCallback;
  1224. #endif
  1225.   pushProcs->show = Nlm_ShowButton;
  1226.   pushProcs->hide = Nlm_HideButton;
  1227.   pushProcs->enable = Nlm_EnableButton;
  1228.   pushProcs->disable = Nlm_DisableButton;
  1229.   pushProcs->remove = Nlm_RemoveButton;
  1230.   pushProcs->setTitle = Nlm_SetButtonTitle;
  1231.   pushProcs->getTitle = Nlm_GetButtonTitle;
  1232.   pushProcs->setPosition = Nlm_SetButtonPosition;
  1233.   pushProcs->getPosition = Nlm_GetButtonPosition;
  1234.  
  1235.   defaultProcs = &(gphprcsptr [1]);
  1236. #ifdef WIN_MAC
  1237.   defaultProcs->click = Nlm_DefaultClick;
  1238.   defaultProcs->key = Nlm_DefaultKey;
  1239.   defaultProcs->draw = Nlm_DrawDefault;
  1240. #endif
  1241. #ifdef WIN_MSWIN
  1242.   defaultProcs->command = Nlm_DefaultCommand;
  1243. #endif
  1244. #ifdef WIN_MOTIF
  1245.   defaultProcs->callback = Nlm_DefaultCallback;
  1246. #endif
  1247.   defaultProcs->show = Nlm_ShowButton;
  1248.   defaultProcs->hide = Nlm_HideButton;
  1249.   defaultProcs->enable = Nlm_EnableButton;
  1250.   defaultProcs->disable = Nlm_DisableButton;
  1251.   defaultProcs->remove = Nlm_RemoveDefaultButton;
  1252.   defaultProcs->setTitle = Nlm_SetButtonTitle;
  1253.   defaultProcs->getTitle = Nlm_GetButtonTitle;
  1254.   defaultProcs->setPosition = Nlm_SetButtonPosition;
  1255.   defaultProcs->getPosition = Nlm_GetButtonPosition;
  1256.   defaultProcs->gainFocus = Nlm_DefaultGainFocus;
  1257.  
  1258.   checkProcs = &(gphprcsptr [2]);
  1259. #ifdef WIN_MAC
  1260.   checkProcs->click = Nlm_CheckClick;
  1261.   checkProcs->draw = Nlm_DrawButton;
  1262. #endif
  1263. #ifdef WIN_MSWIN
  1264.   checkProcs->command = Nlm_CheckCommand;
  1265. #endif
  1266. #ifdef WIN_MOTIF
  1267.   checkProcs->callback = Nlm_CheckCallback;
  1268. #endif
  1269.   checkProcs->show = Nlm_ShowButton;
  1270.   checkProcs->hide = Nlm_HideButton;
  1271.   checkProcs->enable = Nlm_EnableButton;
  1272.   checkProcs->disable = Nlm_DisableButton;
  1273.   checkProcs->remove = Nlm_RemoveButton;
  1274.   checkProcs->setTitle = Nlm_SetButtonTitle;
  1275.   checkProcs->getTitle = Nlm_GetButtonTitle;
  1276.   checkProcs->setStatus = Nlm_SetButtonStatus;
  1277.   checkProcs->getStatus = Nlm_GetButtonStatus;
  1278.   checkProcs->setPosition = Nlm_SetButtonPosition;
  1279.   checkProcs->getPosition = Nlm_GetButtonPosition;
  1280.  
  1281.   radioProcs = &(gphprcsptr [3]);
  1282. #ifdef WIN_MAC
  1283.   radioProcs->click = Nlm_RadioClick;
  1284.   radioProcs->draw = Nlm_DrawButton;
  1285. #endif
  1286. #ifdef WIN_MSWIN
  1287.   radioProcs->command = Nlm_RadioCommand;
  1288. #endif
  1289. #ifdef WIN_MOTIF
  1290.   radioProcs->callback = Nlm_RadioCallback;
  1291. #endif
  1292.   radioProcs->show = Nlm_ShowButton;
  1293.   radioProcs->hide = Nlm_HideButton;
  1294.   radioProcs->enable = Nlm_EnableButton;
  1295.   radioProcs->disable = Nlm_DisableButton;
  1296.   radioProcs->remove = Nlm_RemoveButton;
  1297.   radioProcs->setTitle = Nlm_SetButtonTitle;
  1298.   radioProcs->getTitle = Nlm_GetButtonTitle;
  1299.   radioProcs->setStatus = Nlm_SetButtonStatus;
  1300.   radioProcs->getStatus = Nlm_GetButtonStatus;
  1301.   radioProcs->setPosition = Nlm_SetButtonPosition;
  1302.   radioProcs->getPosition = Nlm_GetButtonPosition;
  1303. }
  1304.